package com.myproject.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller("accountController")
@RequestMapping("/accountController.do")
@SessionAttributes({"a","username"}) //put a and username to session, 
//as a result both request and session have the two attribute.
public class AccountController {

	@RequestMapping(params="method=login")
	public String login(String username, ModelMap map){
		System.out.println("Hello "+ username);
		map.put("a", "Hello "+ username +"!");
		return "main";
	}
	
	@RequestMapping(params="method=register")
	public ModelAndView register(String username){
		System.out.println("Hello "+ username);
		ModelAndView mav =new ModelAndView("account/account_register");
		mav.addObject("username", "peter");
		return mav;
	}
}
